<%@page import="freemarker.template.*,java.util.*,com.fasterxml.jackson.core.*"%>
<%
        //init template engine configure:
        // Initialize the FreeMarker configuration;
        // - Create a configuration instance with the defaults of FreeMarker 2.3.21
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
        // - Templates are stoted in the WEB-INF/templates directory of the Web app.
        cfg.setServletContextForTemplateLoading(
            getServletContext(), "WEB-INF/templates");
        // - Give the standard error page on template errors (HTTP 500, usually):
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        // You should set various other settings in a real app.
        // See the "webapp2" example for them.
        

        // Build the data-model
        // Map root = new HashMap();
     //   String pageDataUrl = getServletContext() + "/4G/xxxxx"; //TODO: load from file
        String pageData = request.getParameter("output_cnt");
        ObjectMapper mapper = new ObjectMapper();
        //解析器支持解析单引号 
        mapper.configure(Feature.ALLOW_SINGLE_QUOTES,true);
        //解析器支持解析结束符
        mapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS,true);
        HashMap jsonMap = mapper.readValue(new java.io.StringReader(pageData),HashMap.class); 

        Map root = jsonMap;//loadPageDataFromJson(pageData);
        root.put("message", "Hello World from freemarker!");
        
        // Get the templat object
        Template t = cfg.getTemplate("test.ftl");
        // Merge the data-model and the template
        try {
            t.process(root, out);
        } catch (TemplateException e) {
            throw new ServletException(
                    "Error while processing FreeMarker template", e);
        }
/*
        static HashMap loadPageDataFromJson(String jsonData){ 
            ObjectMapper mapper = new ObjectMapper();
            //解析器支持解析单引号
            mapper.configure(Feature.ALLOW_SINGLE_QUOTES,true);
            //解析器支持解析结束符
            mapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS,true);
            HashMap jsonMap = mapper.readValue(new java.io.StringReader(jsonData),HashMap.class); 
            return jsonMap;
        }
*/
%>